package com.zt.location.modules.base.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zt.location.common.utils.PageUtils;
import com.zt.location.common.utils.Query;
import com.zt.location.common.utils.R;
import com.zt.location.modules.base.entity.VehicleEntity;
import com.zt.location.modules.base.service.VehicleService;
import com.zt.location.modules.sys.entity.SysUserEntity;

/**
 * 
 * 
 * @author admin
 * @email obj_admin@163.com
 * @date 2019-05-02 14:28:20
 */
@RestController
@RequestMapping("/base/vehicle")
public class VehicleController {
	@Autowired
	private VehicleService vehicleService;

	
	/**
	 * 列表
	 */
	@RequestMapping("/qlist")
	@RequiresPermissions("base:vehicle:qlist")
	public R qlist(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);
		List<VehicleEntity> vehicleList = vehicleService.queryList(query);
		return R.ok().put("vehicle", vehicleList);
	}
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("base:vehicle:list")
	public R list(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);

		List<VehicleEntity> vehicleList = vehicleService.queryList(query);
		int total = vehicleService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(vehicleList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("base:vehicle:info")
	public R info(@PathVariable("id") Integer id) {
		VehicleEntity vehicle = vehicleService.queryObject(id);

		return R.ok().put("vehicle", vehicle);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("base:vehicle:save")
	public R save(@RequestBody VehicleEntity vehicle) {
		String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
		vehicle.setCuser(username);
		vehicleService.save(vehicle);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("base:vehicle:update")
	public R update(@RequestBody VehicleEntity vehicle) {
		vehicleService.update(vehicle);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("base:vehicle:delete")
	public R delete(@RequestBody Integer[] ids) {
		vehicleService.deleteBatch(ids);

		return R.ok();
	}

}
